package com.china.zhuoyue.ui.activity.estate

import android.view.View
import android.widget.TextView
import com.china.zhuoyue.R
import com.china.zhuoyue.databinding.ActivitySmartOpenDoorBinding
import com.china.zhuoyue.ui.base.BaseActivity
import com.china.zhuoyue.ui.cache.UserCache
import com.china.zhuoyue.ui.ext.*
import com.china.zhuoyue.ui.utils.GlideUtils

class SmartOpenDoorActivity : BaseActivity<ActivitySmartOpenDoorBinding>() {
    override fun initView() {
        loadView {
            bindViewClick(ivSmartOpenDoorQuan)
            tabLayout.tabData {
                tab { R.string.text_smart_open_door_xiao_qu.getString() }
                tab { R.string.text_smart_open_door_dan_yuan.getString() }
                tab { R.string.text_smart_open_door_di_ku.getString() }
            }
            val guardTime = "5000"
            bindTextViewValue(tvSmartOpenDoorGuardTime, getString(R.string.text_smart_open_door_guard_time, guardTime), guardTime)

            val guardCount = "4500"
            bindTextViewValue(tvSmartOpenDoorGuardCount, getString(R.string.text_smart_open_door_guard_count, guardCount), guardCount)

            val userCount = "3000"
            bindTextViewValue(tvSmartOpenDoorUserCount, getString(R.string.text_smart_open_door_user_count, userCount), userCount)

            val power = "70"
            bindTextViewValue(tvSmartOpenDoorPower, getString(R.string.text_smart_open_door_power, power), power)

            val status = "正常"
            bindTextViewValue(tvSmartOpenDoorStatus, getString(R.string.text_smart_open_door_status, status), status)

            val record = "4500"
            bindTextViewValue(tvSmartOpenDoorRecord, getString(R.string.text_smart_open_door_record, record), record)
        }
    }

    override fun initData() {
        UserCache.getUserInfoBean().apply {
            GlideUtils.intoView(mThis, avatar, vb.ivHead, placeholder = R.mipmap.icon_mine_default_head)
            vb.tvNickName.text = nickname
        }
    }

    private fun bindTextViewValue(textView: TextView, text: String, span: String) {
        textView.textSpan(text) {
            spanText = span
            addBoldSpan()
            addAbsoluteSizeSpan(15.dp)
            addForegroundColorSpan(R.color.text_color.toColor())
        }
    }

    override fun onClick(v: View?) {
        when (v) {
            vb.ivSmartOpenDoorQuan -> "开启成功".toastMessageLong()
        }
    }
}